<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: ImagePortlet.php 460 2011-01-16 11:45:11Z steen.rabol $
 * @package Pradoportal.Portlets.ImagePortlet
 *
 */

Prado::using('Application.Portlets.Portlet');
Prado::using('Application.Common.Data.PortalConfigRecord');
/**
 * ImagePortlet front end
 *
 */
class ImagePortlet extends Portlet
{
	private	$_portletconfig			= null;

	public function getPortletConfig()
	{
		return $this->_portletconfig;
	}

	protected function getConfigName()
	{
		return get_class() . '_' . $this->Parameters['id'];
	}

	public function onInit($param)
	{
		parent::onInit($param);

		$this->_portletconfig		= unserialize($this->ConfigRecord->value);
		$this->_portletconfig['id']	= $this->ConfigRecord->id;

		if(!isset($this->_portletconfig['cssextra']))
			$this->_portletconfig['cssextra'] = '';

		if(!isset($this->_portletconfig['boxcss']))
			$this->_portletconfig['boxcss'] = 'imageportlet';

		if(!isset($this->_portletconfig['boxcssextra']))
			$this->_portletconfig['boxcssextra'] = '';

	}

	public function onLoad($param)
	{
		parent::onLoad($param);

		if($this->PortletConfig !== null)
		{
			$imagefile = $this->Application->PortalBasePath . "/storage/images/" . $this->PortletConfig['imagename'];
			if($this->PortletConfig['imagename'] != "" && file_exists($imagefile))
			{
				if(isset($this->PortletConfig['cssclass']) && $this->PortletConfig['cssclass'] !="")
				{
					$this->pnlImagePortlet->CssClass=$this->PortletConfig['cssclass'];
				}

				if(isset($this->PortletConfig['page']) && $this->PortletConfig['page'] != "")
				{
					$ctrl = new TPortalHyperLink();
					$ctrl->NavigateUrl	= $this->Service->constructUrl($this->PortletConfig['page']);
					$ctrl->ImageUrl		= $this->Application->Service->Request->BaseUrl . "/storage/images/" . $this->PortletConfig['imagename'];
					$ctrl->ImageWidth				= ($this->PortletConfig['imagewidth'] != "" ? $this->PortletConfig['imagewidth'] . "px;" : '');
					$ctrl->ImageHeight				= ($this->PortletConfig['imageheight'] != "" ? $this->PortletConfig['imageheight'] . "px;" : '');
				}
				else if(isset($this->PortletConfig['imageurl']) && $this->PortletConfig['imageurl'] != "")
				{
					$ctrl = new TPortalHyperLink(); //new THyperlink();
					$ctrl->NavigateUrl	= $this->PortletConfig['imageurl'];
					$ctrl->ImageUrl		= $this->Application->Service->Request->BaseUrl . "/storage/images/" . $this->PortletConfig['imagename'];
					$ctrl->ImageWidth				= ($this->PortletConfig['imagewidth'] != "" ? $this->PortletConfig['imagewidth'] . "px;" : '');
					$ctrl->ImageHeight				= ($this->PortletConfig['imageheight'] != "" ? $this->PortletConfig['imageheight'] . "px;" : '');

				}
				else
				{
					$ctrl = new TImage();
					$ctrl->ImageUrl				= $this->Application->Service->Request->BaseUrl . "/storage/images/" . $this->PortletConfig['imagename'];
					$ctrl->Width				= ($this->PortletConfig['imagewidth'] != "" ? $this->PortletConfig['imagewidth'] . "px;" : '');
					$ctrl->Height				= ($this->PortletConfig['imageheight'] != "" ? $this->PortletConfig['imageheight'] . "px;" : '');
					
					$ctrl->Style->BorderWidth	= TPropertyValue::ensureInteger($this->PortletConfig['imageborder']);
					$ctrl->Style->BorderColor	= TPropertyValue::ensureString($this->PortletConfig['imagebordercolor']);
					$ctrl->Style->BorderStyle	= 'solid';
					$ctrl->Style->CustomStyle	= TPropertyValue::ensureString($this->PortletConfig['cssextra']);
				}

				$this->pnlImagePortlet->Controls[] = $ctrl;

				$this->pnlImagePortlet->CssClass			= TPropertyValue::ensureString($this->PortletConfig['boxcss']);
				$this->pnlImagePortlet->Style->CustomStyle	= TPropertyValue::ensureString($this->PortletConfig['boxcssextra']);
			}
		}
	}
}
?>